<?php
getHeader();

if (!isset($_SESSION['authPassed']))
{
	?>
<div id="content">
<div class="tabs headTabs"><span>发表文章</span></div>
<div class="dataList"><span>请登录后再发表.</span></div>
</div>
	<?php
}
else if (isset($_POST['postStatus']))
{
	$data['postName'] = $_POST['postName'];
	$data['postTime'] = time();
	$data['postGroup'] = $_POST['postGroup'];
	$data['postOwner'] = $_SESSION['uid'];
	$data['postContent'] = $_POST['postContent'];
	$data['postStatus'] = $_POST['postStatus'];
	if ($data['postStatus'] == 'static')
	{
		$comp = compProf::getAdminByCid($_GET['cid']);
		if ($_SESSION['uid'] == $comp)
		{
			$post = new postClass($data);
			if ($post->create())
			{
				?>
<div id="content">
<div class="tabs headTabs"><span>发表成功</span></div>
<div class="dataList"><span>发表成功.</span></div>
</div>
				<?php
			}
			else
			{
				?>
<div id="content">
<div class="tabs headTabs"><span>发表失败</span></div>
<div class="dataList"><span>发表失败.</span></div>
</div>
				<?php
			}
		}
	}
	else
	{
		$post = new postClass($data);
		if ($post->create())
		{
			?>
<div id="content">
<div class="tabs headTabs"><span>发表成功</span></div>
<div class="dataList"><span>发表成功.</span></div>
</div>
			<?php
		}
		else
		{
			?>
<div id="content">
<div class="tabs headTabs"><span>发表失败</span></div>
<div class="dataList"><span>发表失败.</span></div>
</div>
			<?php
		}
	}
}
else if ($_GET['do'] == 'add')
{
	if ($_GET['type'] == 'official')
	{
		$comp = compProf::getAdminByCid($_GET['cid']);
		if ($_SESSION['uid'] == $comp)
		{
			?>
<div id="content">
<div class="tabs headTabs"><span>文章发表</span></div>
<div class="dataList">
<link rel="stylesheet"	href="<?php echo PLUGINURL; ?>tinyEditor/style.css" />
<script type="text/javascript"	src="<?php echo PLUGINURL; ?>tinyEditor/tinyeditor.js"></script>
<ul>
	<form action='?p=editPost' method="post" class='postForm'>
	<li>标题: <input type='text' name='postName' class='postInput' /></li>
	<li><input type='hidden' name='postGroup'
		value='<?php echo $_GET['group']; ?>' /> <input type='hidden'
		name='postStatus' value='static' /></li>
	<li>所属: <?php echo $_GET['group'].' - '.readablePostType($_GET['type']); ?>
	<li>内容: <textarea name='postContent' id="tinyInput"></textarea> <?php getEditor(); ?></li>
	<li><br />
	<input type="submit" value="提交" class="button"
		style='margin-left: 40px;' onclick="instance.post();" /></li>
	
	</form>
</ul>
</div>
</div>
			<?php
		}
		else
		{
			?>
<div id="content">
<div class="tabs headTabs"><span>发表文章</span></div>
<div class="dataList"><span>你没有权限发表文章.</span></div>
</div>
			<?php
		}
	}
	else
	{
		?>
<div id="content">
<div class="tabs headTabs"><span>创建讨论</span></div>
<div class="dataList">
<link rel="stylesheet"
	href="<?php echo PLUGINURL; ?>tinyEditor/style.css" />
<script type="text/javascript"
	src="<?php echo PLUGINURL; ?>tinyEditor/tinyeditor.js"></script>
<ul>
	<form action='?p=editPost' method="post" class='postForm'>
	<li>标题: <input type='text' name='postName' class='postInput' /></li>
	<li><input type='hidden' name='postGroup'
		value='<?php echo $_GET['group']; ?>' /> <input type='hidden'
		name='postStatus' value='open' /></li>
	<li>所属: <?php echo $_GET['group'].' - '.readablePostType($_GET['type']); ?>
	<li>内容: <textarea name='postContent' id="tinyInput"></textarea><?php getEditor(); ?> </li>
	<li><br />
	<input type="submit" value="提交" class="button"
		style='margin-left: 40px;' onclick="instance.post();" /></li>
	
	</form>
</ul>
</div>
</div>
		<?php
	}
}
getPanel();
getFooter();
?>